

package com.idcos.enterprise.portal.web.auto;

// auto generated imports

import com.idcos.cloud.biz.common.permisson.OperateAction;
import com.idcos.cloud.core.common.util.StringUtil;
import com.idcos.cloud.web.common.BaseResultVO;
import com.idcos.cloud.web.common.JsonResultUtil;
import com.idcos.enterprise.portal.form.PortalQueryByPageForm;
import com.idcos.enterprise.portal.form.PortalUserGroupQueryByPageForm;
import com.idcos.enterprise.portal.manager.auto.PortalUserGroupOperateManager;
import com.idcos.enterprise.portal.manager.auto.PortalUserGroupQueryManager;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 用户组管理
 * web层controller相关的接口自动生成，此文件属于自动生成的，请勿直接修改,具体可以参考codegen工程
 * Generated by <tt>controller-codegen</tt> on 2015-10-28 14:17:42.
 *
 * @author jiaohuizhe
 * @version PortalUserGroupController.java, v 1.1 2015-10-28 14:17:42 jiaohuizhe Exp $
 */

@Controller
@OperateAction("F_PORTAL_USERGROUP")
@RequestMapping(value = "/portal/usergroup")
@Api(tags = "04.用户组管理的接口", description = "PortalUserGroupController")
public class PortalUserGroupController {

    //========== manager ==========

    @Autowired
    private PortalUserGroupQueryManager portalUserGroupQueryManager;

    @Autowired
    private PortalUserGroupOperateManager portalUserGroupOperateManager;

    /**
     * 分配角色信息
     *
     * @param id
     * @param selectRoles
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.POST, value = "/{id}/allocate/role")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_CREATE")
    public BaseResultVO allocateRole(@PathVariable String id, @RequestParam("selectRoles") String selectRoles) {
        return JsonResultUtil.getResult(portalUserGroupOperateManager.allocateRole(id, selectRoles));

    }

    /**
     * 分配用户信息
     *
     * @param id
     * @param selectUsers
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.POST, value = "/{id}/allocate/user")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_CREATE")
    public BaseResultVO allocateUser(@PathVariable String id, @RequestParam("selectUsers") String selectUsers) {
        return JsonResultUtil.getResult(portalUserGroupOperateManager.allocateUser(id, selectUsers));

    }

    /**
     * 获取某用户组角色信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/roles/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_GET")
    public BaseResultVO queryRolesById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager.queryRolesById(id));

    }

    /**
     * 获取某用户组权限信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/permissions/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_GET")
    public BaseResultVO queryPermissionsById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager.queryPermissionsById(id));

    }

    /**
     * 获取某用户组用户列表
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/users/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_GET")
    public BaseResultVO queryUsresById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager.queryUsersById(id));

    }

    /**
     * 查询用户所关联的用户组信息
     *
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/page/user")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_GET")
    public BaseResultVO queryGroupPageByUserIdAndCnd(PortalQueryByPageForm form) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager.queryGroupPageByUserIdAndCnd(form));

    }

    /**
     * 查询角色所关联的用户组信息
     *
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/page/role")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_GET")
    public BaseResultVO queryGroupPageByRoleIdAndCnd(PortalQueryByPageForm form) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager.queryGroupPageByRoleIdAndCnd(form));
    }

    /**
     * 获取某用户组信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_GET")
    public BaseResultVO queryById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager.queryById(id));

    }

    /**
     * 删除用户组
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_DELETE")
    public BaseResultVO delete(@PathVariable String id) {
        return JsonResultUtil.getResult(portalUserGroupOperateManager.delete(id));

    }

    /**
     * 更新用户组
     *
     * @param id
     * @param name
     * @param remark
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_PUT")
    public BaseResultVO update(@PathVariable String id, @RequestParam("name") String name,
                               @RequestParam(name = "type", required = false) String type,
                               @RequestParam("remark") String remark) {
        return JsonResultUtil.getResult(portalUserGroupOperateManager.update(id, name, type, remark));

    }

    /**
     * 查询用户组信息
     *
     * @param offset
     * @param limit
     * @param form
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/page/{offset}/{limit}")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_PAGE")
    public BaseResultVO queryByPage(@PathVariable String offset, @PathVariable String limit,
                                    PortalUserGroupQueryByPageForm form, @RequestParam("cnd") String cnd) {
        BaseResultVO resultVO = JsonResultUtil.getResult(portalUserGroupQueryManager.queryByPage(offset, limit, form, cnd));

        return resultVO;

    }

    /**
     * 创建用户组信息
     *
     * @param name
     * @param remark
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.POST, value = "/")
    @ResponseBody
    @OperateAction("O_PORTAL_USERGROUP_CREATE")
    public BaseResultVO create(@RequestParam("tenantId") String tenant, @RequestParam("name") String name,
                               @RequestParam(name = "type", required = false) String type,
                               @RequestParam("remark") String remark) {
        return JsonResultUtil.getResult(portalUserGroupOperateManager.create(tenant, name, type, remark));

    }

    /**
     * 查询字典表用户组类型
     *
     * @param tenantId
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/userGroupType")
    @ResponseBody
    public BaseResultVO getUserGroupType(@RequestParam("tenantId") String tenantId) {
        BaseResultVO resultVO = JsonResultUtil.getResult(portalUserGroupQueryManager.getUserGroupType(tenantId));
        return resultVO;
    }

    /**
     * 根据用户组type和租户id查询用户组集合
     *
     * @param type
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/group/type/tenantId")
    @ResponseBody
    public BaseResultVO queryGroupByTypeAndTenantId(@RequestParam(name = "type", required = false) String type, @RequestParam String tenantId) {
        return JsonResultUtil.getResult(portalUserGroupQueryManager
                .queryGroupByTypeAndTenantId(StringUtil.isBlank(type) ? "default" : type, tenantId));
    }

}
